package com.wicket.okrcalc.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrcalc.biz.service.dto.req.*;
import com.wicket.okrcalc.biz.service.dto.res.*;
import com.wicket.okrcalc.common.exception.BizException;
import com.wicket.okrcalc.common.util.CommonFunctionHelper;
import com.wicket.okrcalc.common.util.RedisUtil;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wicket.okrapp.integration.dto.QueryDeptMemberDedupListComRespDto;
import com.wicket.okrapp.integration.dto.QueryDeptMemberDedupListComReqDto;
import com.wicket.okrcalc.biz.service.dto.common.StandardDataDto;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrcalc.common.exception.Assert;
import com.wicket.okrcalc.biz.service.nb.NbDashboardWorkTask;
import com.wicket.okrapp.integration.FwAppSmallCircleCommonClient;
import com.wicket.okrcalc.biz.service.DashboradStandardDataService;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class DashboardWorkTaskServiceImpl
  implements com.wicket.okrcalc.biz.service.DashboardWorkTaskService {

  @Resource
  private RedisUtil redisUtil;
//@Resource
 //private MCustomFields5Service mCustomFields5Service;
@Resource
  private NbDashboardWorkTask nbDashboardWorkTask;
@Resource
  private FwAppSmallCircleCommonClient fwAppSmallCircleCommonClient;
@Resource
  private DashboradStandardDataService dashboradStandardDataService;
/**
   * D4查询部门任务或问题人员排行列表(公共)[9041]
   * gen by moon at 4/2/2024, 6:30:59 PM
   */
  @Trace(operationName = "D4查询部门任务或问题人员排行列表(公共)")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public QueryDeptTaskQuesMemberRankingListComRespDto queryDeptTaskQuesMemberRankingListCom(QueryDeptTaskQuesMemberRankingListComReqDto reqDto){
    
      
      BatchQueryMultiagentSingleDataPointSubjectChartComRespDto batchQueryMultiagentSingleDataPointSubjectChartComRespDto_1 =null;
//步骤0: M4执行大屏接收字段 - implementDashboardReceiveField
     //ModelCode: receptionService
        ImplementDashboardReceiveFieldRespDto receptionServiceRes = null;
    ImplementDashboardReceiveFieldReqDto receptionServiceReq=new ImplementDashboardReceiveFieldReqDto();
  if(reqDto!=null){
      receptionServiceReq.setDeptId(reqDto.getDeptId());//SimpleFieldAssign//sourceId:1684087_1
receptionServiceReq.setPeriodId(reqDto.getPeriodId());//SimpleFieldAssign//sourceId:1684100_1
receptionServiceReq.setDataType(reqDto.getDataType());//SimpleFieldAssign//sourceId:1684099_1
receptionServiceReq.setDataUsageSceneCode(reqDto.getDataUsageSceneCode());//SimpleFieldAssign//sourceId:1684101_1
receptionServiceReq.setUseScene(reqDto.getUseScene());//SimpleFieldAssign//sourceId:1684089_1
receptionServiceReq.setTableTypeCode(reqDto.getTableTypeCode());//SimpleFieldAssign//sourceId:1684088_1
receptionServiceReq.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1684091_1
receptionServiceReq.setStandardDataOrderType(reqDto.getStandardDataOrderType());//SimpleFieldAssign//sourceId:1686185_1
    }
  
    /*M4接收入参字段[8856]  用于特殊方法接收上游入参。 */
    Assert.isNull(receptionServiceReq.getDeptId(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-部门ID不能为空",false);
Assert.isNull(receptionServiceReq.getPeriodId(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-周期ID不能为空",false);
Assert.isNull(receptionServiceReq.getDataType(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-数据点类型不能为空",false);
Assert.isNull(receptionServiceReq.getDataUsageSceneCode(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-数据业务场景不能为空",false);
Assert.isNull(receptionServiceReq.getUseScene(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-虚拟组织使用场景不能为空",false);
Assert.isNull(receptionServiceReq.getTableTypeCode(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-归属内容表类型编码不能为空",false);
Assert.isNull(receptionServiceReq.getSpaceId(),"D4查询部门任务或问题人员排行列表(公共)-M4接收入参字段-创建于空间ID不能为空",false);
      receptionServiceRes = nbDashboardWorkTask.implementDashboardReceiveField(receptionServiceReq);
      
      
      
    
//步骤1: D3查询部门下人员去重列表(公共) - queryDeptMemberDedupListCom
     QueryDeptMemberDedupListComRespDto queryDeptMemberDedupListComRespDto = null;
    QueryDeptMemberDedupListComReqDto queryDeptMemberDedupListComReqDto=new QueryDeptMemberDedupListComReqDto();
  if(reqDto!=null){
      queryDeptMemberDedupListComReqDto.setDeptId(reqDto.getDeptId());//SimpleFieldAssign//sourceId:1684064_1
queryDeptMemberDedupListComReqDto.setUseScene(reqDto.getUseScene());//SimpleFieldAssign//sourceId:1684065_1
queryDeptMemberDedupListComReqDto.setOwnTableTypeCode(reqDto.getTableTypeCode());//SimpleFieldAssign//sourceId:1684068_1
queryDeptMemberDedupListComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1684063_1
    }
  
    /*D3查询部门下人员去重列表(公共)[9040]   */
    Assert.isNull(queryDeptMemberDedupListComReqDto.getDeptId(),"D4查询部门任务或问题人员排行列表(公共)-D3查询部门下人员去重列表(公共)-部门ID不能为空",false);
Assert.isNull(queryDeptMemberDedupListComReqDto.getUseScene(),"D4查询部门任务或问题人员排行列表(公共)-D3查询部门下人员去重列表(公共)-虚拟组织使用场景不能为空",false);
Assert.isNull(queryDeptMemberDedupListComReqDto.getOwnTableTypeCode(),"D4查询部门任务或问题人员排行列表(公共)-D3查询部门下人员去重列表(公共)-归属内容表类型编码不能为空",false);
Assert.isNull(queryDeptMemberDedupListComReqDto.getSpaceId(),"D4查询部门任务或问题人员排行列表(公共)-D3查询部门下人员去重列表(公共)-创建于空间ID不能为空",false);
      queryDeptMemberDedupListComRespDto = fwAppSmallCircleCommonClient.queryDeptMemberDedupListCom(queryDeptMemberDedupListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
    
//步骤2: D4批量查询多主体单数据点主体图表(公共) - batchQueryMultiagentSingleDataPointSubjectChartCom
     BatchQueryMultiagentSingleDataPointSubjectChartComRespDto batchQueryMultiagentSingleDataPointSubjectChartComRespDto = null;
    if(queryDeptMemberDedupListComRespDto !=null){
          BatchQueryMultiagentSingleDataPointSubjectChartComReqDto batchQueryMultiagentSingleDataPointSubjectChartComReqDto=new BatchQueryMultiagentSingleDataPointSubjectChartComReqDto();
  if(queryDeptMemberDedupListComRespDto!= null&&  queryDeptMemberDedupListComRespDto.getVirtualOrgMemberList() !=null&& !CollectionUtil.isEmpty(queryDeptMemberDedupListComRespDto.getVirtualOrgMemberList())){
      batchQueryMultiagentSingleDataPointSubjectChartComReqDto.setStandardDataList(queryDeptMemberDedupListComRespDto.getVirtualOrgMemberList().stream().map(item->item.getOriginalRoleMemberId())
        .collect(Collectors.toList()));/*list-to-strings*///sourceId:1684077_1
    }
if(reqDto!=null){
      batchQueryMultiagentSingleDataPointSubjectChartComReqDto.setStandardDataOrderType(reqDto.getStandardDataOrderType());//SimpleFieldAssign//sourceId:1686183_1
batchQueryMultiagentSingleDataPointSubjectChartComReqDto.setDataType(reqDto.getDataType());//SimpleFieldAssign//sourceId:1684078_1
batchQueryMultiagentSingleDataPointSubjectChartComReqDto.setPeriodId(reqDto.getPeriodId());//SimpleFieldAssign//sourceId:1684079_1
batchQueryMultiagentSingleDataPointSubjectChartComReqDto.setDataUsageSceneCode(reqDto.getDataUsageSceneCode());//SimpleFieldAssign//sourceId:1684080_1
batchQueryMultiagentSingleDataPointSubjectChartComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1684081_1
    }
  
    /*D4批量查询多主体单数据点主体图表(公共)[8867]   */
    Assert.isNull(batchQueryMultiagentSingleDataPointSubjectChartComReqDto.getDataType(),"D4查询部门任务或问题人员排行列表(公共)-D4批量查询多主体单数据点主体图表(公共)-数据点类型不能为空",false);
Assert.isNull(batchQueryMultiagentSingleDataPointSubjectChartComReqDto.getPeriodId(),"D4查询部门任务或问题人员排行列表(公共)-D4批量查询多主体单数据点主体图表(公共)-周期ID不能为空",false);
Assert.isNull(batchQueryMultiagentSingleDataPointSubjectChartComReqDto.getDataUsageSceneCode(),"D4查询部门任务或问题人员排行列表(公共)-D4批量查询多主体单数据点主体图表(公共)-数据业务场景不能为空",false);
Assert.isNull(batchQueryMultiagentSingleDataPointSubjectChartComReqDto.getSpaceId(),"D4查询部门任务或问题人员排行列表(公共)-D4批量查询多主体单数据点主体图表(公共)-创建于空间ID不能为空",false);
      batchQueryMultiagentSingleDataPointSubjectChartComRespDto = dashboradStandardDataService.batchQueryMultiagentSingleDataPointSubjectChartCom(batchQueryMultiagentSingleDataPointSubjectChartComReqDto)/*vcase invoke isSameApp*/;
      
      
      batchQueryMultiagentSingleDataPointSubjectChartComRespDto_1 = batchQueryMultiagentSingleDataPointSubjectChartComRespDto;
           }
    
QueryDeptTaskQuesMemberRankingListComRespDto retData = new QueryDeptTaskQuesMemberRankingListComRespDto();
  if(batchQueryMultiagentSingleDataPointSubjectChartComRespDto_1!=null){
      retData.setStandardDataList(batchQueryMultiagentSingleDataPointSubjectChartComRespDto_1.getStandardDataList().stream().map(item -> BeanUtil.toBean(item, StandardDataDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1686190_1
    }
  

  
  
return retData;
  }
  //
}
